<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/WEB-INF/taglib/jstl.jsp" %>

<c:set var="isRevise" value="${false}"/>
<c:set var="styleRevise" value="" />
<c:if test="${not empty cdInfo}">
	<c:set var="isRevise" value="${true}"/>
	<c:set var="styleRevise" value="style='background-color:#E3E3E3;' readonly='readonly'" />
</c:if>
<div style="margin:2px 2px 2px 2px;">
	<form id="frmCdReg">
		<table class="left-table">
		<tr>
			<td class="cdTitleTd">코드 유형</td>
			<td class="cdContsTd">
				<c:choose>
					<c:when test="${not empty codeTypes}">
						<select id="cdTpId" name="cdTpId">
							<option value="" selected="selected">- 타입 선택 -</option>
							
							<c:forEach var="items" items="${codeTypes}" varStatus="i">
								<c:set var="selectedOpt" value="" />
								<c:if test="${isRevise && items.cdTpId == cdInfo.cdTpId}">
									<c:set var="selectedOpt" value="selected='selected'" />
								</c:if>
							
								<option value="${items.cdTpId}" ${selectedOpt}>${items.cdTpAlias} (${items.cdTpId})</option>	
							</c:forEach>
						</select>
					</c:when>
											
					<c:otherwise> 사용할 수 있는 코드 유형이 없습니다. </c:otherwise>
				</c:choose>
			</td>
		</tr>
		
		<c:choose>
			<c:when test="${isRevise}">
			<tr>
				<td class="cdTitleTd" style="height:44px;"><p>코드 생성 규칙</p></td>
				<td class="cdContsTd">
					<p id="cdTpRegExpr" style="display:none;"></p>
					<p style="color:blue; padding-bottom:4px;">코드 유형을 변경해도 생성 규칙은 변경되지 않습니다.</p>
					<p>${cdInfo.cdRegExpr}</p>
				</td>
			</tr>
			</c:when>
			<c:otherwise>
			<tr>
				<td class="cdTitleTd" style="height:44px;"><p>코드 생성 규칙</p><p>(Optional)</p></td>
				<td class="cdContsTd">
					<p style="color:blue; padding-bottom:4px;">코드 유형에서 정의된 규칙입니다.</p>
					<p id="cdTpRegExpr">
						<c:choose>
							<c:when test="${isRevise && not empty cdInfo.cdTpRegExpr}">${cdInfo.cdTpRegExpr}</c:when>
							<c:otherwise><span id="noneMsg">코드 유형을 선택하세요.</span></c:otherwise>
						</c:choose>
					</p>
				</td>
			</tr>
			</c:otherwise>
		</c:choose>
		
		<tr>
			<td class="cdTitleTd">코드</td>
			<td class="cdContsTd">
				<span><input type="text" id="cdId" name="cdId" value="${cdInfo.cdId}" ${styleRevise} /></span>
				<c:if test="${isRevise}"><span style="color:blue;">코드는 변경할 수 없습니다.</span></c:if>
			</td>
		</tr>
		<tr>
			<td class="cdTitleTd">코드 명칭</td>
			<td class="cdContsTd"><input type="text" id="cdAlias" name="cdAlias" value="${cdInfo.cdAlias}" /></td>
		</tr>		
		<tr>
			<td class="cdTitleTd">사용 여부</td>
			<td class="cdContsTd">
				<c:set var="cdUseY" value="checked='checked'" />
				<c:set var="cdUseN" value="" />
				<c:if test="${isRevise && cdInfo.cdUseYN == 'N'}">
					<c:set var="cdUseY" value="" />
					<c:set var="cdUseN" value="checked='checked'" />
				</c:if>

				<input type="radio" name="cdUseYN" value="Y" ${cdUseY} />Y
				&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" name="cdUseYN" value="N" ${cdUseN} />N
			</td>
		</tr>		
		<tr>
			<td class="cdTitleTd" style="height:86px;">설명</td>
			<td class="cdContsTd">
				<textarea id="cdDesc" name="cdDesc" style="width:95%; height:80px; resize:none;">${cdInfo.cdDesc}</textarea>
			</td>
		</tr>
		</table>
	</form>
</div>
<div class="cdBtnsDiv">
	<c:choose>
	<c:when test="${isRevise}"><input type="button" id="jqwFormReviseSaveBtn" value="수정" /></c:when>
	<c:otherwise><input type="button" id="jqwFormSaveBtn" value="저장" /></c:otherwise>
	</c:choose>

	<input type="button" id="jqwCloseBtn" value="닫기" />
</div>

<script type="text/javascript" src="/resources/js/views/template/system/code/_regForm.js"></script>
<script type="text/javascript" src="/resources/js/views/template/system/code/_regFormValid.js"></script>